import threading
import time

lock=threading.Lock()
start = time.time()
n=0
def task1():
    global n
    lock.acquire()
    for i in range(10000000):
        n+=1
    print("task1中的n的值为{}".format(n))
    lock.release()

def task2():
    global n
    lock.acquire()
    for i in range(10000000):
        n+=1
    print("task2中的n的值为{}".format(n))
    lock.release()

if __name__=="__main__":
    th1=threading.Thread(target=task1,name="th1")
    th2=threading.Thread(target=task2,name="th2")
    th1.start()
    th2.start()
    th1.join()
    th2.join()
    end=time.time()
    print(n,(end-start))